#ifndef CVREALTIMEPAINT_H
#define CVREALTIMEPAINT_H

#include "qgraphicsscene.h"
#include <QObject>
#include <QDropEvent>
#include <QDebug>
#include <QPainter>
#include <QPen>
#include <QBrush>
#include <QPointF>
#include <QtCore/QtMath>


/*
    drawListItem()类 记录所有图元的类型,点阵
    cvRealtimePaint()类  在场景中画图,保存场景中的图元,作图流程
*/
class drawListItem
{
public:
    enum drawType{
        typeNull,
        typeLine=1,
        typeAngle,
        typeRect,
        typeCircle,
        typePolygons,
        typeCaliCircle,
        typeCaliLine,
        typeMax
    };

    drawListItem(int type);

    int drawingType;    //线 角 方形 圆形 多边形
    int maxPoints;      //最大点阵数量
    int drawPointNum;   //当前花点的位置
    int isValid;        //图案是否完成,是否有效,无效扇区


    QList<QPointF> drawPoints;//图形所有点的列表

    bool drawAddPoint(QPointF);
    bool drawSubPoint(void);
};



class cvRealtimePaint : public QObject
{

    Q_OBJECT

public:
    enum drawState{
        waitingFristPoint,
        waitingMoving,
        drawingGraph,
        drawEnd,
    };
    Q_ENUM(drawState);

    enum drawType{
        typeNull,
        typeLine=1,
        typeAngle,
        typeRect,
        typeCircle,
        typePolygons,
        typeCaliCircle,
        typeCaliLine,
        typeMax
    };
    Q_ENUM(drawType);

    int drawingType;    //当前画图的类型
    int drawingStatus;  //当前画图的状态
    float umPerPixel;

    QGraphicsScene DrawScene;           //场景
    QList<drawListItem> drawingLists;   //item列表
    QPen pen;
    QColor brush_color;
    QBrush brush;

    explicit cvRealtimePaint(QObject *parent = nullptr);

    void dataReset();
    void cleanInvalidPoints(void);
    bool drawingNullMode(void);
    bool drawingLineMode();
    bool drawingCircleMode();
    bool drawingAngleMode();
    bool drawingSquarenessMode();
    bool drawingPolygeonMode();
    bool drawingDelLastItem();

    QRectF *PointsToQtCircle(QPointF p1, QPointF p2, QPointF p3);

    void manualDrawCircle(QList<QRectF> cboxs);
    void drawLineInGroup();
    void setPixelGain(float in);

public slots:
    void slots_mouse_left_press(QMouseEvent *event);
    void slots_mouse_right_press(QMouseEvent *event);

    void slots_mouse_release(QMouseEvent *event);
    void slots_mouse_move(QMouseEvent *event);

signals:

};

#endif // CVREALTIMEPAINT_H
